teamcity.Project = function(json) {
    teamcity.Loader.call(this, json);

    this.element = document.createElement("div");
    this.labelElement = document.createElement("div");
    this.labelElement.className = "section-label";
    this.labelElement.innerHTML = this.json["@name"];
    this.element.appendChild(this.labelElement);

    this.childrenElement = document.createElement("div");
    this.childrenElement.className = "section-children";
    this.element.appendChild(this.childrenElement);

    this.labelElement.addEventListener("click", this.clickHandler_.bind(this), false);
};

teamcity.Project.prototype.clickHandler_ = function(event) {
    if (this._expanded) {
        this._expanded = false;
        this.childrenElement.className = "section-children";
    } else {                
        this._expanded = true;
        this.childrenElement.className = "section-children-expanded";
    }
    this.load();
};

teamcity.Project.prototype.onLoaded = function(json) {

}

teamcity.Project.prototype.__proto__ = teamcity.Loader.prototype;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
teamcity.BuildType = function(json) {
    teamcity.Loader.call(this, json);

    this.json["@href"] += "/builds"; //little hack

    this.element = document.createElement("div");
    this.labelElement = document.createElement("div");
    this.labelElement.className = "buildType";
    this.labelElement.innerHTML = this.json["@name"];
    this.element.appendChild(this.labelElement);

    this.childrenElement = document.createElement("div");
    this.childrenElement.className = "section-children";
    this.element.appendChild(this.childrenElement);

    this.labelElement.addEventListener("click", this.clickHandler_.bind(this), false);
};

teamcity.BuildType.prototype.clickHandler_ = function(event) {
    if (this._expanded) {
        this._expanded = false;
        this.childrenElement.className = "section-children";
    } else {
        this._expanded = true;
        this.childrenElement.className = "section-children-expanded";
    }
    this.load();
};

teamcity.BuildType.prototype.onLoaded = function(json) {
    var builds = json.build;
    for (var i = 0; i < builds.length; i++) {
        var build = new teamcity.Build(builds[i]);
        this.childrenElement.appendChild(build.element);
    }
}

teamcity.BuildType.prototype.__proto__ = teamcity.Loader.prototype;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
teamcity.Build = function(json) {
    teamcity.Loader.call(this, json);

    this.element = document.createElement("div");
    this.element.className = "build-element";

    this.statusImage = document.createElement("img");
    if ("SUCCESS" == this.json["@status"]) {
        this.statusImage.src = "/img/buildStates/success_small.gif";
    } else {
        this.statusImage.src = "/img/buildStates/error_small.gif";
    }
//    this.statusImage.style = "float: left;";
    this.element.appendChild(this.statusImage);

    this.textElement = document.createElement("div");
    this.textElement.className = "build-text";
    this.textElement.innerHTML = "Loading...";
    this.element.appendChild(this.textElement);

    this.load();
//    this.childrenElement = document.createElement("div");
//    this.childrenElement.className = "section-children";
//    this.element.appendChild(this.childrenElement);

//    this.labelElement.addEventListener("click", this.clickHandler_.bind(this), false);
};

teamcity.Build.prototype.clickHandler_ = function(event) {
    if (this._expanded) {
        this._expanded = false;
        this.childrenElement.className = "section-children";
    } else {
        this._expanded = true;
        this.childrenElement.className = "section-children-expanded";
    }
    this.load();
};

teamcity.Build.prototype.onLoaded = function(json) {
    this.textElement.innerHTML = json.statusText;
}

teamcity.Build.prototype.__proto__ = teamcity.Loader.prototype;
